package com.nl.controller.web.mapper.impl;


import com.nl.controller.web.bean.SmsAllStation;
import com.nl.controller.web.bean.SmsBaseStation;
import com.nl.controller.web.bean.XuYiStation;
import com.nl.controller.web.bean.sendLimit.QxjSendScope;
import com.nl.controller.web.mapper.SmsAreaMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @author zh
 * @date 2020-5-26 11:08:58
 */
@Slf4j
@Repository
public class SmsAreaMapperImpl implements SmsAreaMapper {
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;
    @Override
    public String getRegionId() {
        return null;
    }

    @Override
    public int checkBaseStationByid(String mgrId) {
        return 0;
    }

    @Override
    public int insertSmsBaseStation(List<SmsBaseStation> list) {
        return 0;
    }

    @Override
    public String checkBaseStation(SmsBaseStation smsBaseStation) {
        return null;
    }

    @Override
    public int delSmsBaseStation(String mgrId) {
        return 0;
    }

    @Override
    public String qryRegionId(String mgrId) {
        return null;
    }

    @Override
    public List<SmsAllStation> findAllStation(Map<String, Object> map) {
        return null;
    }

    @Override
    public List<SmsAllStation> findAllStationByCounty(Map<String, Object> map) {
        return null;
    }

    @Override
    public int updateMgrTemplateInfo(String id, String regionType, String regionTypeValue, String msisdn, String cityId, String resultRegionId) {
        return 0;
    }

    @Override
    public int findHeatMapLevel() {
        return 0;
    }

    @Override
    public int qxjScopeSave(String scopeId, String cityId, String scopeType, String longAndLats) {
        return 0;
    }

    @Override
    public QxjSendScope qxjScopeQry(String scopeId) {
        return null;
    }

    @Override
    public List<XuYiStation> findXuYiStations() {
        return null;
    }

  

    @Override
    public int addSmsBaseStationTemp(List<SmsBaseStation> list) {
        SqlSession session = null;
        int result = 0;
        try {
            Date date1 = new Date();
            session = sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH,false);
            //每次提交1000条
            int a = 1000;
            int loop = (int) Math.ceil(list.size() / (double) a);

            List<SmsBaseStation> tempList = new ArrayList<>(a);
            int start, stop=0;
            for (int i = 0; i < loop; i++) {
                tempList.clear();
                start = i * a;
                stop = Math.min(i * a + a - 1, list.size() - 1);
                log.info("range:" + start + " - " + stop);
                for (int j = start; j <= stop; j++) {
                    tempList.add(list.get(j));
                }
                session.insert("addSmsBaseStationTemp", tempList);
                session.clearCache();
                log.info("已经插入" + (stop + 1) + " 条");
            }
            session.commit();
            result=stop;
            Date date2=new Date();
            long time=date2.getTime()-date1.getTime();
            log.info("共耗时"+time+"毫秒");
        } catch (Exception e) {
            e.printStackTrace();
            session.rollback();
            result=0;
        } finally {
            if (session != null) {
                session.close();
            }
        }
        return result;
    }

    @Override
    public int delStationTemp(String mgrId) {
        return 0;
    }

    @Override
    public int addStation(String id) {
        return 0;
    }

	@Override
	public List<String> findXuYiSubPathNames() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<String> findXuYiSubStationNames(String subPathName) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<String> findXuYiSubStationNameLike(String pathName, String regionName) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<XuYiStation> findXuYiSubStationNameLike2(String regionName, List<String> regionNameList) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<XuYiStation> findXuYiSubStations(String pathName, String regionName, String subSeq) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<XuYiStation> findXuYiSubStations3(String pathName, String subStationName) {
		// TODO Auto-generated method stub
		return null;
	}
}
